package com.my.behaviourtype.memento;

import java.util.Date;

/**
 * 
  Originator
      原发器创建一个备忘录,用以记录当前时刻它的内部状态。
      使用备忘录恢复内部状态.

 */
public class Originator {
	private String state;
	private Date time;
	
	// snap a state to create memento
	public Memento createMemento(){
		return new Memento(this.state, new Date());
	}
	
	// use memento to recovery
	public void useMemento(Memento memento) {
		this.state = memento.getState();
		this.time = memento.getTime();
	}
	
	public void execute() {
		System.out.println("I'm " + state + " in " + (time == null ? "now" : time));
	}

	/**
	 * @return the state
	 */
	public String getState() {
		return state;
	}

	/**
	 * @param state the state to set
	 */
	public void setState(String state) {
		this.state = state;
	}
	
	/**
	 * @return the time
	 */
	public Date getTime() {
		return time;
	}

	/**
	 * @param time the time to set
	 */
	public void setTime(Date time) {
		this.time = time;
	}
}
